package Day13;

import java.io.*;

/**
 * @Author kalista
 * @Description 文件字符流
 * @Date 2020/11/19  14:31
 **/
public class TestFileCoyp2 {
    public static void main(String[] args) {


        File file = new File("f:\\d.txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        File file1 = new File("f:\\e.txt");
        if (!file1.exists()) {
            try {
                file1.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        FileReader fileReader = null;
        FileWriter fileWriter = null;
        try {

            fileReader = new FileReader(file);
            fileWriter = new FileWriter(file1);

            char[] buffer = new char[1024];
            int len = 0;
            while ((len = fileReader.read(buffer)) != -1){
               fileWriter.write(buffer,0,len);
                String s = new String(buffer);
                System.out.println(s);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileReader.close();
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        System.out.println("拷贝完成");
    }
}
